import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/layout'
// import store from '@/store'

Vue.use(VueRouter)

const routes = [
  // 我的钱包路由
  { path: '/money', name: 'money', component: () => import('@/views/my/components/money') },
  // 我的优惠券
  { path: '/coupon', name: 'coupon', component: () => import('@/views/my/components/coupon') },
  { path: '/login', name: 'login', component: _ => import('@/views/login') },
  {
    path: '/',
    // name: 'layout', // 如果父路由有默认子路由,那它的 name没有意义
    component: Layout,
    children: [
      // 默认页面
      { path: '', name: 'home', component: _ => import('@/views/shopping/home') },
      // 搜索
      { path: '/search', name: 'SearchIndex', component: () => import('@/views/search/search') },
      // 我的页面(主页面)
      { path: '/my', name: 'my', required: '/my', component: () => import('@/views/my') },
      // 购物车
      { path: '/goodscar', name: 'goodscar', component: _ => import('@/views/shopping/goods-car/goods-car.vue') },
      // 周边店铺
      {
        path: '/hh',
        name: 'hh',
        component: () => import('@/views/confirmation') // 看订单确认页面效果
      },
      // 黄恢翔
      { path: '/order', name: 'order', component: () => import('@/views/order-details') },
      // \黄恢翔
      // 支付完成
      {
        path: '/pay',
        name: 'pay',
        component: () => import('@/views/confirmation/component/pay-success')
      },
      // 周边店铺------韦锋盛
      { path: '/nearbyShops', component: _ => import('../views/nearbyShops.vue') },
      // 我的商圈------韦锋盛
      { path: '/myMall', component: _ => import('../views/myMall.vue') },
      // 我的商圈------韦锋盛
      { path: '/myMall', component: _ => import('../views/myMall.vue') },
      // 周边店铺------韦锋盛
      { path: '/nearbyShops', component: _ => import('../views/nearbyShops.vue') }
      // { path: '/shop', name: 'shop', component: _ => import('@/views/my/components/goods-car.vue') }
    ]
  },
  // 夏姣 购物车路由
  { path: '/shop', name: 'shop', component: _ => import('../views/shopping/goods-car/goods-car.vue') },

  // 胡李宇
  { path: '/goods', name: 'goods', component: _ => import('@/views/shopping/goods') },
  { path: '/goods/buy', name: 'goodsBuy', component: _ => import('@/views/shopping/goods/components/goods-buy.vue') },
  // \胡李宇

  // 支付成功页面
  {
    path: '/shippingAddress',
    name: 'shippingAddress',
    component: () => import('@/views/my/components/address/shipping-address')
  },
  // 新增地址
  {
    path: '/addAddress',
    name: 'addAddress',
    component: () => import('@/views/my/components/address/add-newAddress')
  },
  // 修改地址
  {
    path: '/editAddress',
    name: 'editAddress',
    component: () => import('@/views/my/components/address/edit-address')
  },
  // 帮助中心
  {
    path: '/help',
    name: 'help',
    component: () => import('@/views/my/components/help')
  },
  // 收藏店铺
  {
    path: '/sellectStore',
    name: 'sellectStore',
    component: () => import('@/views/my/components/collectStore')
  },
  // 申请开店
  {
    path: '/Store',
    name: 'Store',
    component: () => import('@/views/my/components/Store')
  },
  {
    path: '/applyOpenStore',
    name: 'applyOpenStore',
    component: () => import('@/views/my/components/Store/components/applyOpenStore')
  },
  {
    path: '/myPromotion',
    name: 'myPromotion',
    component: () => import('@/views/my/components/myPromotion')
  },
  {
    path: '/promotion',
    name: 'promotion',
    component: () => import('@/views/my/components/promotion')
  }
]

const router = new VueRouter({
  routes
})

// // 挂载路由守卫
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') return next()
//   // 获取token
//   const tokenStr = store.state.token
//   if (!tokenStr) return next('/login')
//   next()
// })

export default router
